/**
 * 
 */
package br.com.cept.sce.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import br.com.cept.sce.commons.util.DAOManager;
import br.com.cept.sce.dominio.impl.Perfil;

/**
 * @author Junier Amorim
 *
 */
public class PerfilDAO {
	
	public List<Perfil> listarTodosPerfis() throws Exception{
		Perfil u = null;
		List<Perfil> resultList = null;
		EntityManager entityManager = DAOManager.getEntityManager();
		
		Query query = entityManager.createQuery("from Perfil order by nome");
		
		resultList = query.getResultList();
	
		return resultList;
	}
	
	public Perfil carregarPerfil(Long id) throws Exception{
		Perfil p = null;
		List<Perfil> resultList = null;
		EntityManager entityManager = DAOManager.getEntityManager();
		
		Query query = entityManager.createQuery("from Perfil p where p.id = :id");
		query.setParameter("id", id);
		
		resultList = query.getResultList();
		
		if(resultList.size() > 0)
			p = resultList.get(0);
		return p;
	}

}
